package com.company;

import java.util.Scanner;

/**
 * @description:
 * @author: 10445
 * @date: Created in 2020/6/8 17:38
 * @version: v1.0
 * @modified By:
 */
public class Sense {

    private Person person = new Person();
    private MonsterWolf monsterWolf1 =new MonsterWolf();
    private MonsterWolf monsterWolf2 =new MonsterWolf();
    private MonsterWolf monsterWolf3 = new MonsterWolf();

    private MonsterWolf littlebossbang = new MonsterWolf();
    private MonsterWolf littlebossgui = new MonsterWolf();
    private MonsterWolf littleboss = new MonsterWolf();
    private MonsterWolf aobing = new MonsterWolf();

    private WeaponDrug weaponDrug = new WeaponDrug();

    private MonsterWolfSet monsterWolfSet = new MonsterWolfSet();

    //private WeaponDrug weaponDrug = new WeaponDrug("drug","药水",+50);


    private Ui ui = new Ui();

    private Room currentRoom;
    private RoomSet roomSet = new RoomSet();

    public Sense() {
        createRooms();
    }
    public void createRooms() {
        Room birth, normal1, normal2, littleboss1, littleboss2,altar,boss;

        //	制造房间
        birth = new Room("出生地");
        normal1 = new Room("普通关卡1");
        normal2 = new Room("普通关卡2");
        littleboss1 = new Room("蚌精窝");
        littleboss2 = new Room("龟丞相窝");
        altar = new Room("祭坛");
        boss = new Room("敖丙房间");

        //	初始化房间的出口
       birth.setExits(normal1,null,null,null,null,null,null,null,null,null);
       normal1.setExits(littleboss1,normal2,null,null,null,null,null,null,null,null);
       normal2.setExits(littleboss2,null,null,normal1,altar,null,null,null,null,null);
       littleboss1.setExits(null,littleboss2,normal1,null,null,altar,null,null,null,null);
       littleboss2.setExits(null,null,normal2,littleboss1,null,null,null,null,null,null);
       altar.setExits(null,null,null,null,littleboss1,normal1,null,null,boss,null);
       boss.setExits(null,null,null,null,null,null,null,null,null,altar);
       currentRoom = birth;  //	从城堡门外开始

        birth.addmonsterwolves(monsterWolf1);
        normal1.addmonsterwolves(monsterWolf2);
        normal2.addmonsterwolves(monsterWolf3);
        littleboss1.addmonsterwolves(littlebossbang);
        littleboss2.addmonsterwolves(littlebossgui);
        altar.addmonsterwolves(littleboss);
        boss.addmonsterwolves(aobing);
        littleboss1.addmonsterwolves(weaponDrug);//这里将药水看成了一种生物


    }


    public void initSense(){
        initPerson();
        initMonster();
        initDrug();

    }
    public void initPerson(){
        person.setId("201902138");
        person.setDescription("小徐");
        person.setHPValue(200);
        person.setCurrentWeapon(new WeaponSword("w1","倚天剑",-50));
    }


    public void initMonster(){
        monsterWolf1.setId("wolf1");
        monsterWolf1.setDescription("lang1");
        monsterWolf1.setHPValue(200);
        monsterWolf1.setCurrentWeapon(new WeaponKnife("mw1","大刀",-10));


        monsterWolf2.setId("wolf2");
        monsterWolf2.setDescription("lang2");
        monsterWolf2.setHPValue(200);
        monsterWolf2.setCurrentWeapon(new WeaponKnife("mw2","大刀",-5));

        monsterWolf3.setId("wolf3");
        monsterWolf3.setDescription("lang3");
        monsterWolf3.setHPValue(200);
        monsterWolf3.setCurrentWeapon(new WeaponKnife("mw3","大刀",-10));

        littlebossbang.setId("littleboss1");
        littlebossbang.setDescription("蚌精");
        littlebossbang.setHPValue(200);
        littlebossbang.setCurrentWeapon(new WeaponKnife("littleboss1","大刀",-15));

        littlebossgui.setId("littleboss2");
        littlebossgui.setDescription("龟丞相");
        littlebossgui.setHPValue(300);
        littlebossgui.setCurrentWeapon(new WeaponKnife("littleboss2","大刀",-5));

        littleboss.setId("littleboss");
        littleboss.setDescription("祭坛怪");
        littleboss.setHPValue(200);
        littleboss.setCurrentWeapon(new WeaponKnife("littleboss","大刀",-10));

        aobing.setId("boss");
        aobing.setDescription("敖丙");
        aobing.setHPValue(300);
        aobing.setCurrentWeapon(new WeaponKnife("boss","大刀",-10));

        monsterWolfSet.getMonsterWolves().add(monsterWolf1);
        monsterWolfSet.getMonsterWolves().add(monsterWolf2);
        monsterWolfSet.getMonsterWolves().add(monsterWolf3);
        monsterWolfSet.getMonsterWolves().add(littlebossbang);
        monsterWolfSet.getMonsterWolves().add(littlebossgui);
        monsterWolfSet.getMonsterWolves().add(littleboss);
        monsterWolfSet.getMonsterWolves().add(aobing);

    }

    public void initDrug(){
        weaponDrug.setId("drug");
        weaponDrug.setDescription("生命药水");
        weaponDrug.setCurrentWeapon(new WeaponKnife("假武器","jia",50));
        weaponDrug.setHPValue(350);
        monsterWolfSet.getMonsterWolves().add(weaponDrug);
    }



    public boolean judgeSuccess(){
        boolean flagPersonSuccess = true;

        if (aobing.getHPValue() <=0){
            flagPersonSuccess=false;
        }

       return flagPersonSuccess;
    }
    public void goRoom(String direction) {
        Room nextRoom = currentRoom.getExit(direction);

        if (nextRoom == null) {
            System.out.println("那里没有门！");
        } else {
            currentRoom = nextRoom;
            showPromt();
        }
    }

    public void showPromt(){
        System.out.println("你在" + currentRoom);
        System.out.print("出口有: ");
        System.out.println(currentRoom.getExitDesc());
        System.out.println("当前房间有怪物：");
        currentRoom.ShowMonsterWolves();
        System.out.println(person.getDescription()+person.getHPValue());

    }


    public void play(){
        ui.displayStaus(this);

        Scanner in = new Scanner(System.in);
        while (true){
            //用户输入命令
            String command = in.nextLine();
            String[] words = command.split(" ");

            //操作命令
            //
            if(words[0].equals("bye"))
            {
                ui.displayBye();
                System.exit(0);
            }else if(words[0].equals("help")){
                ui.displayHelpMsg();
            }else if (words[0].equals("chop")){
                this.getPerson().useArticle(this.getPerson().getCurrentWeapon(),
                        this.getMonsterWolfSet().get(words[1]));

                //管理
                for (MonsterWolf item:this.getMonsterWolfSet().getMonsterWolves()
                ) {
                    if (item.getHPValue()< 0) {
                        this.getMonsterWolfSet().getMonsterWolves().remove(item);//!!
                        break;
                    }
                }
                ui.displayDamageMsg(this.getPerson(),this.getMonsterWolfSet().get(words[1]));

                //妖怪随机砍人   改成受攻击生物反击 我觉得这样比较人性化
                this.getMonsterWolfSet().get(words[1]).useArticle(this.getMonsterWolfSet().get(words[1]).getCurrentWeapon(),this.getPerson());
                /*for (MonsterWolf item:this.getMonsterWolfSet().getMonsterWolves()
                     ) {
                    if (1==Utils.randomMonsterChop(0,2)){
                        item.useArticle(item.getCurrentWeapon(),this.getPerson());
                        ui.displayDamageMsg(item,this.getPerson());
                    }
                }*/
                ui.displayDamageMsg(this.getMonsterWolfSet().get(words[1]),this.getPerson());
                showPromt();
            }else if (words[0].equals("go")){
                goRoom(words[1]);
            }
            else if (words[0].equals("888888")){
                person.setCurrentWeapon(new WeaponSword("w1","屠龙刀",-70));
                System.out.println("你的武器升级了，变为屠龙刀，伤害值爆棚");
            } else{
                ui.displayError();
                ui.displayHelpMsg();
                ui.displayStaus(this);
            }


            if (judgeSuccess()==false){
                System.out.println("你成功了勇士，你从龙宫出来了，游戏结束");
                System.exit(0);
            }



        }

    }

    public Person getPerson() {
        return person;
    }

    public void setPerson(Person person) {
        this.person = person;
    }


    public MonsterWolfSet getMonsterWolfSet() {
        return monsterWolfSet;
    }

    public void setMonsterWolfSet(MonsterWolfSet monsterWolfSet) {
        this.monsterWolfSet = monsterWolfSet;
    }

    public Room getCurrentRoom() {
        return currentRoom;
    }

    public void setCurrentRoom(Room currentRoom) {
        this.currentRoom = currentRoom;
    }

}
